﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using Com.Toook.Common;
using System.Data.SQLite;

public partial class movie_play : BaseShowPage
{
    protected MovieObject movie = new MovieObject();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            InitMovie();
        }
    }
    private void InitMovie()
    {
        int id = ParamHelper.ParseIntPositive(Request["id"]);

        string sql = "select id, title, url, case imgLocal when length(imgLocal) > 1 then imgLocal else img end as img," +
            " type, actor, director, year, area, content, likeCount, clickCount from MoviePublish where id=@id";
        SQLiteConnection conn = SqliteHelper.GetConnection("SQLiteDatabase");
        SQLiteCommand cmd = new SQLiteCommand(sql, conn);
        cmd.Parameters.Add("@id", DbType.Int32).Value = id;
        SQLiteDataReader reader = null;

        try
        {
            conn.Open();
            reader = cmd.ExecuteReader();
            movie.Title = reader["title"].ToString();
            movie.Url = reader["url"].ToString();
            movie.Img = reader["img"].ToString();
            movie.Actor = reader["actor"].ToString();
            movie.Area = reader["area"].ToString();
            movie.Content = reader["content"].ToString();
            movie.Director = reader["director"].ToString();
            int n;
            movie.ClickCount = int.TryParse(reader["clickCount"].ToString(), out n) ? n : 1;
            movie.LikeCount = int.TryParse(reader["likeCount"].ToString(), out n) ? n : 1;
            movie.MovieType = reader["type"].ToString();
            movie.Score = int.TryParse(reader["score"].ToString(), out n) ? n : 5;
            movie.Year = int.TryParse(reader["year"].ToString(), out n) ? n : 2000;
        }
        finally
        {
            SqliteHelper.CloseDbResource(conn, reader);
        }
    }
}